package com.heatup.apt.management.controller;

import com.heatup.apt.common.util.RequestTools;
import com.heatup.apt.management.service.AddressService;
import com.heatup.apt.model.TSysCity;
import com.heatup.apt.model.TSysDistrice;
import com.heatup.apt.model.TSysProvince;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by b3st9u on 16/9/19.
 */
@Controller
@RequestMapping("system/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    @ResponseBody
    @RequestMapping(value = "/province.action")
    public List<TSysProvince> getProvinces(HttpServletRequest request, HttpServletResponse response) {
        List<TSysProvince> provinceList = addressService.queryAllProvince();
        return provinceList;
    }

    @ResponseBody
    @RequestMapping(value = "/city.action")
    public List<TSysCity> getCityes(HttpServletRequest request, HttpServletResponse response) {
        long provinceId = RequestTools.RequestLong(request, "provinceId", 0);
        List<TSysCity> cityList = addressService.queryCityByProvinceId(provinceId);
        return cityList;
    }

    @ResponseBody
    @RequestMapping(value = "/districe.action")
    public List<TSysDistrice> getDistrices(HttpServletRequest request, HttpServletResponse response) {
        long cityId = RequestTools.RequestLong(request, "cityId", 0);
        return addressService.queryDistriceByCityId(cityId);
    }
}
